//
//  UpdateUserNameViewController.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/3.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "UpdateUserNameViewController.h"
#import "MineViewModel.h"

@interface UpdateUserNameViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UIButton *updateClick;

@property (nonatomic,strong) MineViewModel * mineViewModel;
@end

@implementation UpdateUserNameViewController

-(MineViewModel *) mineViewModel{
    if (!_mineViewModel) {
        _mineViewModel = [[MineViewModel alloc] init];
    }
    return _mineViewModel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navigationItem setTitle:@"修改昵称"];
    [self.view setBackgroundColor:DEF_COLOR_F0F0F0];
    
    self.userName.placeholder = UserInfoShare.userCenterModel.userName;
    
    /**
     修改昵称
     */
    [[self.updateClick rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        
        if ([MXUtility NSNULLString:self.userName.text]) {
            [MXUtility showTips:@"昵称不能为空哦～"];
            return ;
        }
        
        [self updateNameNetWork];
        
    }];
    
}
-(void) updateNameNetWork{

    [MXUtility showMBProgress:self.view message:LoadingText];
    [[self.mineViewModel updateUserNameRequestParameter:self.userName.text] subscribeNext:^(id x) {
        
        if ([x[@"errorcode"] integerValue] == 0) {
            
            [MXUtility showTips:@"修改昵称成功～"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
        [MXUtility hideMBProgress:self.view];
    }error:^(NSError *error) {
        [MXUtility hideMBProgress:self.view];
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
